// TrackEditorDoc.cpp : implementation of the CTrackEditorDoc class
//

#include "stdafx.h"
#include "TrackEditor.h"

#include "TrackEditorDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CTrackEditorDoc

IMPLEMENT_DYNCREATE(CTrackEditorDoc, CDocument)

BEGIN_MESSAGE_MAP(CTrackEditorDoc, CDocument)
	ON_COMMAND(ID_INSERIR_RETA, OnInserirReta)
	ON_COMMAND(ID_INSERIR_CURVA_ESQ, OnInserirCurvaEsquerda)
	ON_COMMAND(ID_INSERIR_CURVA_DIR, OnInserirCurvaDireita)
END_MESSAGE_MAP()


// CTrackEditorDoc construction/destruction

CTrackEditorDoc::CTrackEditorDoc()
{
	// TODO: add one-time construction code here
	iNTracks = 1;
	sTrack[0] = CARACTER_SIMBOLO_RETA_INICIO;
	sTrack[1] = CARACTER_SIMBOLO_FINAL_CIRCUITO;
}

CTrackEditorDoc::~CTrackEditorDoc()
{
}

const char* CTrackEditorDoc::GetTracks()
{
	return sTrack;
}

BOOL CTrackEditorDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	iNTracks = 1;
	sTrack[0] = CARACTER_SIMBOLO_RETA_INICIO;
	sTrack[1] = CARACTER_SIMBOLO_FINAL_CIRCUITO;

	return TRUE;
}

void CTrackEditorDoc::OnInserirReta()
{
	if (iNTracks == NMAX_TRACKS) return;
	sTrack[iNTracks++] = CARACTER_SIMBOLO_RETA_NORMAL;
	sTrack[iNTracks] = CARACTER_SIMBOLO_FINAL_CIRCUITO;

	SetModifiedFlag();
	UpdateAllViews(NULL);
}

void CTrackEditorDoc::OnInserirCurvaEsquerda()
{
	if (iNTracks == NMAX_TRACKS) return;
	sTrack[iNTracks++] = CARACTER_SIMBOLO_CURVA_ESQUERDA;
	sTrack[iNTracks] = CARACTER_SIMBOLO_FINAL_CIRCUITO;

	SetModifiedFlag();
	UpdateAllViews(NULL);
}

void CTrackEditorDoc::OnInserirCurvaDireita()
{
	if (iNTracks == NMAX_TRACKS) return;
	sTrack[iNTracks++] = CARACTER_SIMBOLO_CURVA_DIREITA;
	sTrack[iNTracks] = CARACTER_SIMBOLO_FINAL_CIRCUITO;

	SetModifiedFlag();
	UpdateAllViews(NULL);
}

// CTrackEditorDoc serialization

void CTrackEditorDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		for (int index = 0; index <= iNTracks; index++)
		{
			ar << sTrack[index];

			if (sTrack[index] == 'F')
				break;
		}
	}
	else
	{
		// TODO: add loading code here
		iNTracks = 0;
		for (int index = 0; index < NMAX_TRACKS; index++)
		{
			ar >> sTrack[index];

			if (sTrack[index] == 'F')
				break;

			iNTracks++;
		}
	}
}


// CTrackEditorDoc diagnostics

#ifdef _DEBUG
void CTrackEditorDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CTrackEditorDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CTrackEditorDoc commands
